//
//  NCChatGuideView.m
//  Masonry
//
//  Created by LINAICAI on 2018/5/7.
//

#import "NCChatGuideView.h"

@interface NCChatGuideView()

@property (nonatomic , strong)UIImageView *bgImage;
@property (nonatomic , strong)UIButton *closeButton;
@end
@implementation NCChatGuideView
- (UILabel*)mainLabelWith:(NSString *)string{
    UILabel *label = [[UILabel alloc]init];
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = 5; //设置行间距
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paraStyle};
    
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:string attributes:dic];
    label.attributedText = attributeStr;
    

    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:14];
    label.numberOfLines = 0;
    return label;
}
- (UILabel*)subLabelWith:(NSString *)string{
    UILabel *label = [[UILabel alloc]init];
    label.text = string;
    label.textColor = [UIColor lightGrayColor];
    label.font = [UIFont systemFontOfSize:12];
    label.numberOfLines = 0;
    return label;
}
- (UIButton *)closeButton{
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setImage:NCChatUIImage(@"close") forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeButton;
}
- (UIImageView *)bgImage{
    if (!_bgImage) {
        _bgImage = [UIImageView new];
        _bgImage.image = NCChatUIImage(@"window");
        _bgImage.contentMode = UIViewContentModeScaleAspectFit;
        
        
    }
    return _bgImage;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *bgView = [[UIView alloc]initWithFrame:frame];
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        
        //添加到要有毛玻璃特效的控件中
        UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
        effectView.frame = self.bounds;
        [self addSubview:effectView];
        
        [self addSubview:self.bgImage];
        [self addSubview:self.closeButton];
        
        [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.centerY.offset(-50);
            make.size.mas_equalTo(self.bgImage.image.size);
        }];
        [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bgImage.mas_bottom).mas_offset(15);
            make.centerX.equalTo(self.bgImage);
        }];
        
        UILabel *label1 = [self mainLabelWith:@"1.可在右上角菜单里查看承包方详情和邀请招标讨论组成员"];
        [self.bgImage addSubview:label1];
        [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.offset(150);
        }];
        
        UILabel *label2 = [self mainLabelWith:@"2.为了提高项目沟通效率和质量，建议在早上9点至晚上9点之间进行项目洽谈"];
        [self.bgImage addSubview:label2];
        [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.equalTo(label1.mas_bottom).offset(18);
        }];
        
        UILabel *label3 = [self mainLabelWith:@"3.为了保持视频谈判良好的节奏,建议您分三阶段进行沟通"];
        [self.bgImage addSubview:label3];
        [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.equalTo(label2.mas_bottom).offset(18);
        }];
 
        UILabel *label4 = [self subLabelWith:@"·阶段①"];
        [self.bgImage addSubview:label4];
        [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.equalTo(label3.mas_bottom).offset(16);
        }];
        
        UILabel *label5 = [self mainLabelWith:@"进行在线答疑"];
        [self.bgImage addSubview:label5];
        [label5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.equalTo(label4.mas_bottom).offset(10);
        }];
        
        UILabel *label6 = [self subLabelWith:@"·阶段②"];
        [self.bgImage addSubview:label6];
        [label6 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.equalTo(label5.mas_bottom).offset(12);
        }];
        
        UILabel *label7 = [self mainLabelWith:@"针对综合实力、技术方案及价格进行议标谈判"];
        [self.bgImage addSubview:label7];
        [label7 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.equalTo(label6.mas_bottom).offset(10);
        }];
        
        UILabel *label8 = [self subLabelWith:@"·阶段③"];
        [self.bgImage addSubview:label8];
        [label8 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.equalTo(label7.mas_bottom).offset(12);
        }];
        
        UILabel *label9 = [self mainLabelWith:@"对潜在中标人交底"];
        [self.bgImage addSubview:label9];
        [label9 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(60);
            make.right.offset(-60);
            make.top.equalTo(label8.mas_bottom).offset(10);
        }];
        

    }
    return self;
}
- (void)showInView:(UIView *)view{
    [view endEditing:YES];
    [view addSubview:self];
    self.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        self.alpha = 1.0;
    } completion:^(BOOL finished) {

    }];
}
- (void)close{
    self.alpha = 1.0;
    [UIView animateWithDuration:0.25 animations:^{
        self.alpha = 0.0;
    } completion:^(BOOL finished) {
        if (finished) {
            [self removeFromSuperview];
        }
    }];
    
}
@end
